package com.infore.dataStatistics.main.cal.chain;

import com.infore.common.base.Msg;
import com.infore.dataStatistics.main.cal.Calculator;
import com.infore.dataStatistics.main.dto.StatTask;
import lombok.Data;

import java.util.List;

@Data
public class RealChain implements Calculator.Chain {

    private StatTask statTask;

    private List<Calculator> cals;

    private int index;

    public RealChain(StatTask statTask, List<Calculator> cals, int index){
        this.statTask = statTask;
        this.cals = cals;
        this.index = index;
    }

    @Override
    public StatTask getTask() {
        return statTask;
    }

    @Override
    public Msg<Object> proceed(StatTask task) {
        Msg<Object> res = null;

        if (cals.size() > index){
            RealChain realChain = new RealChain(statTask, cals, index + 1);
            Calculator cal = cals.get(index);
            res = cal.deal(realChain);
        }

        return res;
    }
}
